/*
 *    Copyright 2008-2009 The Digester Tools Team
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */
package com.digestertools.annotations.addressbook;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import lombok.Data;

import com.digestertools.annotations.AttributeCallParam;
import com.digestertools.annotations.BeanPropertySetter;
import com.digestertools.annotations.CallMethod;
import com.digestertools.annotations.CallParam;
import com.digestertools.annotations.ObjectCreate;
import com.digestertools.annotations.SetNext;
import com.digestertools.annotations.SetProperty;

/**
 * 
 * @author Simone Tripodi
 * @version $Id: Person.java 357 2009-12-16 20:00:36Z simone.tripodi $
 */
@Data
@ObjectCreate(pattern = "address-book/person")
public class Person {

    private final Map<String, String> emails = new HashMap<String, String>();

    private final List<Address> addresses = new ArrayList<Address>();

    @SetProperty(pattern = "address-book/person")
    private int id;

    @SetProperty(pattern = "address-book/person")
    private String category;

    @BeanPropertySetter(pattern = "address-book/person/name")
    private String name;

    /** we assume only one email of each type... */
    @CallMethod(pattern = "address-book/person/email")
    public void addEmail(@AttributeCallParam(attribute = "type") String type,
            @CallParam String address) {
        this.emails.put(type, address);
    }

    @SetNext
    public void addAddress(Address addr) {
        this.addresses.add(addr);
    }

}
